void swapi(int i,int j,int size,int base[]){
     long long a;unsigned long long b;
     if (base[i]<0 || base[j]<0){
        a=base[i];
        base[i]=base[j];
        base[j]=a;
     }
     else{
          b=base[i];
          base[i]=base[j];
          base[j]=b;
     }
}
int comp(int a,int b,int h[]){
    if (h[a]>h[b])
       return 1;
    if (h[a]<h[b])
       return -1;
    return 0;
}
void down_heap(int i,int num,int h[],int size){
     int max=i;
     if (2*i<=num && comp(max,2*i,h)<0)
        max=2*i;
     if (2*i+1<=num && comp(max,2*i+1,h)<0)
        max=2*i+1;
     if (max!=i){
        swapi(max,i,size,h);
        down_heap(max,num,h,size);
     }
}
void heapsort(int base[],int num,int size){
     int i;
     for (i=num/2;i;--i)
         down_heap(i,num,base,size);
     for (i=num;i>1;--i){
         swapi(1,i,size,base);
         down_heap(1,i-1,base,size);
     }
}
